package com.teach;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;


public class LocalDateTimeTest {
	
	public static void main(String[] args) {
		LocalDateTime dateTime = LocalDateTime.now();
		System.out.println(dateTime);
		dateTime = LocalDateTime.of(2021, 1, 2, 3, 4);
		System.out.println(dateTime);
		System.out.println(dateTime.getYear());
		System.out.println(dateTime.get(ChronoField.YEAR));
		LocalDateTime d1 = dateTime.minusDays(3);
		System.out.println(dateTime);
		System.out.println(d1);
		LocalDateTime d2 = dateTime.plusHours(50);
		System.out.println(d2);
		LocalDateTime d3 = dateTime.withMonth(12);
		System.out.println(d3);
		
		DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy年M月dd日HH时mm分ss秒SSS毫秒 a hh 周u E");
		String str = df.format(dateTime);
		System.out.println(str);
		DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
		str = "2011-12-13 14:15";
		dateTime = LocalDateTime.parse(str, df1);
		System.out.println(dateTime);
		
	}

}
